package net.byg.task;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import net.byg.quartz.Quartz;

import java.text.ParseException;

public class SchedualRunTask implements Runnable {
	private Object obj;

	public SchedualRunTask(Object bussinessUtil) {
		super();
		this.obj = bussinessUtil;
	}

	public void run() {
		try {
			String rundate = null;
			Quartz quartz = new Quartz();
			SchedulerFactory sf = new StdSchedulerFactory();
			String JOB_GROUP_NAME = "group1";
			String TRIGGER_GROUP_NAME = "trigger1";
			String jobName = "11";
			Scheduler sched = sf.getScheduler();
			JobDetail jobDetail = new JobDetail(jobName, JOB_GROUP_NAME, quartz.getClass());// 任务名，任务组，任务执行类
			jobDetail.getJobDataMap().put("myjob", obj);
			// 触发器
			CronTrigger trigger = new CronTrigger(jobName, TRIGGER_GROUP_NAME);// 触发器名,触发器组

			trigger.setCronExpression(rundate);
			// 触发器时间设定
			sched.scheduleJob(jobDetail, trigger);
			// 启动
			if (!sched.isShutdown()) {
				sched.start();
			}

		} catch (ParseException e) {
			e.printStackTrace();
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}

}
